1. Field of the Invention
Methods and apparatuses consistent with the present invention relate to an allocation of a buffer, and more particularly, to a method and apparatus for allocating a buffer that is to be used by a plurality of modules sequentially processing data.
2. Description of the Related Art
Currently, the development of Internet communication has increased the types and numbers of data. Accordingly, the types and numbers of programs for processing data have also increased. However, since different programs had to be developed even when data having a similar format or type is processed, resources were unnecessarily wasted. In order to solve this problem, a pipe and filter architecture is preferred to process the data.
The pipe and filter architecture is used to process specific data by combining independent modules that are named components or filters. An example of using the pipe and filter architecture is the processing of MP3 music files. In this case, an MP3 file can be reproduced by combining an input module, an MP3 decoding module, and an output module.
In more detail, the input module reads MP3 data that is to be reproduced.
The MP3 decoding module generates pulse coded modulation (PCM) data by applying an MP3 decoding algorithm to the read MP3 data.
The output module outputs the generated PCM data as sound through a speaker, thereby completing the processing of the MP3 data.
As described above, by processing data using the pipe and filter architecture, modules can be reused, and by combining a plurality of modules, various types of data can be processed. However, since each of a plurality of modules for processing data operates independently, one of the modules processes the data, the processing result is transferred to another module, and another module processes the received data, and thus, this may be inefficient when an interaction between modules, such as allocation of a buffer, is needed. That is, since each module is independent, any one module cannot know information regarding previous and subsequent modules, and in particularly, since buffer allocation methods applied to respective modules are different from each other, several negotiation processes between previous and subsequent modules are needed in a buffer allocation.
FIG. 1 illustrates a buffer allocation needed to process data in a conventional pipe and filter architecture.
Referring to FIG. 1, in order to process the data, a first module 101 and a second module 102 are sequentially used.
When the first module 101 allocates a buffer to be used, the first module 101 receives from the second module 102 second capacity information regarding a buffer capacity needed for the second module 102 to process the data. The first module 101 checks if the second capacity information received from the second module 102 can be transposed with first capacity information regarding the capacity of a storage space needed for data processing in the first module 101. If the first capacity information can be transposed with the second capacity information, the first module 101 allocates a buffer by using only the first capacity information and informs the second module 102 of this buffer allocation. However, if the first capacity information cannot be transposed with the second capacity information, a separate job is needed to allocate an appropriate size of a buffer to be used by the first module 101, and the first module 101 and the second module 102 must perform a complex buffer allocation process for the job, and this is called a buffer negotiation process.
For example, when the first module 101 outputs data in a unit of 1000 bytes whereas the second module 102 must input data in a unit of 2000 bytes, the first capacity information may not be transposed with the second capacity information. Thus, the first module 101 must perform a complex buffer negotiation process in order to allocate an appropriate size of a buffer.
A method of allocating a buffer to be used by the first module 101 and the second module 102 will now be described.
In general, sections of a buffer 100, in which data is stored, are discontinuous. When the buffer 100 is initially used, since data is stored from the beginning of the buffer 100, the data is continuously stored in the beginning portion of the buffer 100, and no data is stored in the last portion of the buffer 100. Thereafter, portions in which data is stored and portions in which no data is stored appear discontinuously in the buffer 100 due to operations, such as discontinuous deletion of data.
The first module 101 allocates a buffer space needed for data processing thereof. Referring to FIG. 1, an A buffer space 110 is allocated as a storage space needed for the data processing in the first module 101.
The second module 102 allocates a buffer space needed for data processing thereof. Referring to FIG. 1, since a storage space needed for the data processing in the second module 102 is greater than an N−1 buffer space 131, the second module 102 cannot allocate the N−1 buffer space 131. Thus, a B buffer space 120 is allocated as the storage space needed for the data processing in the second module 102.
In a conventional buffer allocation method, the A buffer space 110 used by the first module 101 and the B buffer space 120 used by the second module 102 are discontinuously distributed. When a buffer is allocated using this method, the following problems may occur.
First, since the conventional buffer allocation method uses a buffer scatteredly, it is inconvenient to manage the buffer.
Second, according to the conventional buffer allocation method, a data processing result of the first module 101 is stored in the A buffer space 110. Since the second module 102 processes data consecutively after the first module 101, the second module 102 needs data stored in the A buffer space 110. Thus, the data stored in the A buffer space 110 must be copied to the B buffer space 120, and since this data copy delays a data processing time, it is inefficient.
Third, according to the conventional buffer allocation method, the A buffer space 110 can be allocated as a maximum size so that data processed by the first module 101 can be smoothly stored. Thus, in most cases, the first module 101 does not use a portion of the A buffer space 110. Due to this, a buffer space is unnecessarily wasted.
Fourth, in order to overcome a problem that a buffer space is unnecessarily wasted, the A buffer space 110 can be allocated as a proper size (for example, an average value) not a maximum size. In this case, if a size of data processed by the first module 101 is greater than the A buffer space 110, a problem occurs. If a size of data processed by the first module 101 is greater than the A buffer space 110, the processed data cannot be immediately stored in the A buffer space 110. That is, if data previously stored in the A buffer space 110 is used by the second module 102, the previously stored data must be deleted and the data processed by the first module 101 must be stored. Thus, data processing of the first module 101 is delayed.